class School: pass
class Department: pass
class Instructor: pass
class Subject: pass
class Student: pass
class School:
    def __init__(self, name):
        self.name = name
        self.departments = []
        self.students = []

    def add_department(self, dept: Department):
        if dept not in self.departments:
            self.departments.append(dept)

    def enroll_student(self, student: Student):
        if student not in self.students:
            self.students.append(student)

class Department:
    def __init__(self, name, school: School):
        self.name = name
        self.school = school
        self.instructors = []
        self.subjects = []

    def add_instructor(self, inst: Instructor):
        if inst not in self.instructors:
            self.instructors.append(inst)

    def add_subject(self, subj: Subject):
        if subj not in self.subjects:
            self.subjects.append(subj)


class Instructor:
    def __init__(self, name, department: Department):
        self.name = name
        self.department = department
        self.subjects_taught = []
        department.add_instructor(self)

    def assign_subject(self, subject: Subject):
        if len(self.subjects_taught) < 3 and subject not in self.subjects_taught:
            self.subjects_taught.append(subject)


class Subject:
    def __init__(self, title, department: Department):
        self.title = title
        self.department = department
        department.add_subject(self)


class Student:
    def __init__(self, name):
        self.name = name
        self.enrolled_subjects = []  # 1..5 -- * Subject (关联)

    def enroll_subject(self, subject: Subject):
        # 满足约束：参加 1-5 门课程学习 (在实际应用中需要运行时检查)
        if len(self.enrolled_subjects) < 5 and subject not in self.enrolled_subjects:
            self.enrolled_subjects.append(subject)
